<?php
// +----------------------------------------------------------------------
// | FileName: AtlasController.php
// +----------------------------------------------------------------------
// | Date: 2023/3/24 16:35:27
// +----------------------------------------------------------------------
// | Author: 默毅 <moyi@mymoyi.cn>
// +----------------------------------------------------------------------
// | Notes: AI的图集 API
// +----------------------------------------------------------------------
	
	namespace App\Controller\Api;
	
	use App\Controller\AbstractController;
	use App\Model\Ai\Atlas\Atlas;
	use App\Model\Ai\Atlas\AtlasList;
	use App\Model\Ai\Drawing\DrawingLora;
	use App\Model\Ai\Drawing\DrawingModel;
	use App\Model\Ai\Drawing\DrawingSampler;
	use App\Model\Ai\Drawing\DrawingVae;
	use App\Model\Ai\Picture;
	use App\Service\Library\CommonService;
	use Hyperf\Di\Annotation\Inject;
	use Hyperf\HttpServer\Annotation\AutoController;
	use Hyperf\Redis\Redis;
	
	#[AutoController]
	class ModelController extends AbstractController
	{
		#[Inject]
		private CommonService $CommonService;
		
		#[Inject]
		private Redis $Redis;
		
		public function info()
		{
			$key = $this->request->input('key');
			$type = $this->request->input('type');
			switch ($type){
				case 'sampler':
					$info = DrawingSampler::with('drawing_server:ai_drawing_server.gpu_name,ai_drawing_server.user_id,ai_drawing_server.name,ai_drawing_server.usage,ai_drawing_server.gpu_ram,ai_drawing_server.ram')->where(['name'=>$key])->first();
					break;
				case 'lora':
					$info = DrawingLora::with('drawing_server:ai_drawing_server.gpu_name,ai_drawing_server.user_id,ai_drawing_server.name,ai_drawing_server.usage,ai_drawing_server.gpu_ram,ai_drawing_server.ram')->where(['name'=>$key])->first();
					break;
				case 'vae':
					$info = DrawingVae::with('drawing_server:ai_drawing_server.gpu_name,ai_drawing_server.user_id,ai_drawing_server.name,ai_drawing_server.usage,ai_drawing_server.gpu_ram,ai_drawing_server.ram')->where(['hash'=>$key])->first();
					break;
				default:
					$info = DrawingModel::with('drawing_server:ai_drawing_server.gpu_name,ai_drawing_server.user_id,ai_drawing_server.name,ai_drawing_server.usage,ai_drawing_server.gpu_ram,ai_drawing_server.ram')->where(['hash'=>$key])->first();
					break;
			}
			
			if($info){
				return $this->success('',$info->toArray());
			}
			return $this->success('数据库翻到里都么得');

			$where = [
				['status', '=', 'normal'],
				['atlas_id','=',$id]
			];
			$list = AtlasList::where($where)
				->get(['picture_id as id']);
			$pic = Picture::with('clip_tag_zh:ai_tag_zh.text,ai_tag_zh.label')
				->with('deepbooru_tag_zh:ai_tag_zh.text,ai_tag_zh.label')
				->find($list,['id','title','prompt','negative_prompt','url','model_name','model_hash','story']);
			
			$where = [
				['status', '=', 'normal'],
				['total', '>', '0'],
			];
//			print_r($list->toArray());
			return $this->success('错误测试',$pic->toArray());
		
		}
	}